package com.jinbao.springbootinit.config;

import lombok.Data;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
//application.yml文件读取为前缀为“sping.redis"的配置项
@ConfigurationProperties(prefix = "spring.redis")
@Data
public class RedissonConfig {
    public Integer database;
    public String host;
    public Integer port;


    @Bean
    public RedissonClient getRedissonClient(){
        Config config=new Config();
        config.useSingleServer()
                .setDatabase(database)
                .setAddress("redis://"+host+":"+port);
        RedissonClient redisson= Redisson.create(config);
        return redisson;

    }



}
